package com.truthbean.jeetb.utils.web;

import java.util.ArrayList;

public class Table {
    private ArrayList<Row> rows = null;
    private boolean echoTableTag = false;

    public void setEchoTableTag(boolean v) {
        this.echoTableTag = v;
    }

    public Table() {
        this.rows = new ArrayList<Row>();
    }

    public void addRow(Row r) {
        this.rows.add(r);
    }

    public String toString() {
        StringBuilder html = new StringBuilder();
        if (echoTableTag)
            html.append("<table>");
        for (Row r : rows) {
            html.append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
            for (Column c : r.getColumns()) {
                html.append("<td nowrap>");
                String vv = Utils.htmlEncode(Utils.getStr(c.getValue()));
                if (vv.equals(""))
                    vv = "&nbsp;";
                html.append(vv);
                html.append("</td>");
            }
            html.append("</tr>");
        }
        if (echoTableTag)
            html.append("</table>");
        return html.toString();
    }
}